<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">

			<title>价格维护</title>

			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<%@ include file="/WEB-INF/jsp/common/header.jsp" %>
				<%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

					<script type="text/javascript">
						$(function () {
							$('#startTime').datebox('setValue', getBeforeCurrentDate90Days());
							$('#endTime').datebox('setValue', getNowFormatDate());
							bindgrid();
						});
					</script>
					<script>
						function del(node) {
							$.ajax({
								type: "delete",
								url: 'purchase/bill/delete?' + 'bilId=' + bilId,
								//                dataType: "xml",				
								success: function (data) {
									$.messager.alert('消息', data.msg);
									$('#add').window('close');
									bindgrid();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}

						function save() {
							if (!$('#fm').form('validate')) {
								return;
							}
							var model = {
								groId: $('#groId').textbox('getValue'),
								bilId: $('#bilId').textbox('getValue'),
								bilCode: $('#bilCode').textbox('getValue'),
								bilPrice: $('#bilPrice').textbox('getValue'),
								bilNum: $('#bilNum').textbox('getValue'),
								bilTaxPrice: $('#bilTaxPrice').textbox('getValue'),
								bilTotalPrice: $('#bilTotalPrice').textbox('getValue'),
								bilDate: $('#bilDate').textbox('getValue'),
								bilRecordDate: $('#bilRecordDate').textbox('getValue'),
								createTime: $('#createTime').textbox('getValue'),
								createName: $('#createName').textbox('getValue'),
								createId: $('#createId').textbox('getValue'),
								updateId: $('#updateId').textbox('getValue'),
								updateName: $('#updateName').textbox('getValue'),
								updateTime: $('#updateTime').textbox('getValue'),
								delFlag: $('#delFlag').textbox('getValue'),
								status: $('#status').textbox('getValue'),
								remark: $('#remark').textbox('getValue'),
								groCode: $('#groCode').textbox('getValue'),
								groName: $('#groName').textbox('getValue')
							};
							$.ajax({
								type: "post",
								dataType: "json",
								url: 'purchase/bill/save',
								data: JSON.stringify(model),
								contentType: "application/json",
								success: function (data) {
									if (data.code != 60200) {
										$.messager.alert('消息', data.msg);
									} else {
										$.messager.alert('消息', data.msg);
										let dg = $('#dg');
										dg.datagrid('enableFilter');
										dg.datagrid('load');
										$('#add').window('close');
									}
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							})

						}

						function editrow() {
							//编辑用户
							var row = $('#dg').datagrid('getSelected');
							if (row) {
								$('#add').window('open');
								$('#fm').form('load', row);

							} else {
								$.messager.alert('消息', '请选中一条数据');
							}
						}
					</script>
					<script>
						/**
						 *  按条件查询报价列表
						 */
						function selectList() {
							var startTime = $('#startTime').datebox('getValue')
							var endTime = $('#endTime').datebox('getValue')
							var status = $('#status').combobox('getValue');
							var dg = $('#dg');
							dg.datagrid('enableFilter');
							dg.datagrid('load', {
								startTime: startTime ? startTime : '',
								endTime: endTime ? endTime : '',
								status: status ? status : ''
							});
						}

						function bindgrid() {
							var startTime = $('#startTime').datebox('getValue')
							var endTime = $('#endTime').datebox('getValue')
							var status = $('#status').combobox('getValue');
							$('#dg').datagrid({
								title: '',
								queryParams: {
									startTime: startTime,
									endTime: endTime,
									status: status
								},
								url: "purchase/bill/selectList",
								iconCls: 'icon-application',
								width: getWidth(0.98),
								height: 400,
								nowrap: true,
								rownumbers: true,
								animate: false,
								collapsible: false,
								clientPaging: false,
								remoteFilter: true,
								filterDelay: 0,
								singleSelect: true,
								pagination: true,
								remoteSort: true,
								frozenColumns: [[]],
								columns: [[{
									field: 'groId',
									title: '批次id',
									sortable: true,
									hidden: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'bilId',
									title: '发票id',
									sortable: true,
									hidden: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'bilCode',
									title: '发票号',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'bilPrice',
									title: '发票金额',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val.toLocaleString()) : '';
									}
								}, {
									field: 'bilNum',
									title: '发票数量',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val.toLocaleString()) : '';
									}
								}, {
									field: 'bilTaxPrice',
									title: '发票税额',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val.toLocaleString()) : '';
									}
								}, {
									field: 'bilTotalPrice',
									title: '价税合计',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val.toLocaleString()) : '';
									}
								}, {
									field: 'bilDate',
									title: '发票日期',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'bilRecordDate',
									title: '过账日期',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'createTime',
									title: '创建时间',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'createName',
									title: '创建人',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'status',
									title: '状态',
									sortable: true,
									formatter: function (val, rec) {
										let status = val ? val : '';
										return unescape(status == '0' ? '待提交' : '已提交');
									}
								}, {
									field: 'remark',
									title: '备注',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'groCode',
									title: '批次编码',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'groName',
									title: '批次名称',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}]],
								toolbar: [],
								onLoadSuccess: function () {
								},
								onDblClickRow: function () {
									editrow();
								}
							});
							$('#dg').datagrid('enableFilter');
						}

						// 导出采购计划列表
						function exportList() {
							let startTime = $('#startTime').datebox('getValue')
							let endTime = $('#endTime').datebox('getValue')
							let status = $('#status').combobox('getValue')

							var form = [];
							form.push('startTime=' + (startTime ? startTime : ''));
							form.push('endTime=' + (endTime ? endTime : ''));
							form.push('status=' + (status ? status : ''));
							console.log('form:', form)
							let url = 'api/purchase/bill/export'
							let xhr = new XMLHttpRequest()
							xhr.open('POST', url, true)
							xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
							xhr.setRequestHeader('token', localStorage.getItem('token'));
							xhr.setRequestHeader('userType', localStorage.getItem('userType'));
							xhr.responseType = 'blob'
							xhr.onload = function () {
								if (this.status == 200) {
									let blob = this.response
									let reader = new FileReader()
									reader.readAsDataURL(blob)
									reader.onload = function (e) {
										let a = document.createElement('a')
										a.download = '采购发票' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
										a.href = e.target.result
										$('body').append(a)
										a.click()
										$(a).remove()
									}
								}
							}
							xhr.send(form.join('&'))
						}
					</script>
					<style scoped="scoped">
						.textbox {
							height: 20px;
							margin: 0;
							padding: 0 2px;
							box-sizing: content-box;
						}

						/*.table tr {
        height: 15px;
    }*/
					</style>
					<div class="query_criteria" id="query_criteria">
						<div style="margin: 5px 0px">
							<%-- 搜索框 --%>
								<label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
									name="startTime" id="startTime"
									data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
									value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
									class="easyui-datebox" name="endTime" id="endTime"
									data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
									style="width: 150px" /> <label
									style="margin-left: 20px; font-size: 12px;">状态：</label> <input
									class="easyui-combobox" id="status" name="status" style="width: 80px;" data-options="valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '全部',
							value: ''
						},{
							label: '待提交',
							value: '0',
							selected:true
						},{
							label: '已提交',
							value: '1'
						}]">
								</select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
									class="easyui-linkbutton" data-options="iconCls:'icon-search'"
									onclick="selectList()">查询</a><a id="export" style="margin-left: 10px"
									href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-export'" onclick="exportList()">导出</a>
						</div>

						<table id="dg"></table>

						<div id="add" class="easyui-window" closed="true" modal="true" title="发票信息"
							style="width: 500px; height: 450px; padding: 10px 20px">
							<form id="fm" class="ssec-form">
								<table class="table">
									<!-- <tr>
										<td>
											<div class="ssec-label">批次id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="groId" name="groId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">发票id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilId" name="bilId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
									<tr>
										<td>
											<div class="ssec-label">发票号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilCode" name="bilCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">发票金额：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilPrice" name="bilPrice" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">发票数量：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilNum" name="bilNum" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">发票税额：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilTaxPrice" name="bilTaxPrice" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">价税合计：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilTotalPrice" name="bilTotalPrice" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">发票日期：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilDate" name="bilDate" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">过账日期：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="bilRecordDate" name="bilRecordDate" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">创建时间：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="createTime" name="createTime" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">创建人：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="createName" name="createName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<!-- <tr>
										<td>
											<div class="ssec-label">create_id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="createId" name="createId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
									<!-- <tr>
										<td>
											<div class="ssec-label">update_id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="updateId" name="updateId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">update_name：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="updateName" name="updateName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">update_time：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="updateTime" name="updateTime" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">del_flag：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="delFlag" name="delFlag" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">status：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="status" name="status" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">remark：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="remark" name="remark" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
									<tr>
										<td>
											<div class="ssec-label">批次编码：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="groCode" name="groCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">批次名称：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="groName" name="groName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
								</table>
								<!-- <div style="padding: 5px; text-align: right;">
									<a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
								</div> -->
							</form>
						</div>
					</div>
		</body>

		</html>